﻿using System;
namespace Moonlite.ExtensionApi.XimlInterfaces
{
    public class DescriptorBase
    {
        private IXimlNode node;
        private DescriptorBase parent;
        private DescriptorBaseCollection children = new DescriptorBaseCollection();
        private Guid guid;
        private object tag;
        public IXimlNode Node
        {
            get { return node; }
            internal set { node = value; }
        }
        public DescriptorBase Parent
        {
            get { return parent; }
            internal set { parent = value; }
        }
        public DescriptorBaseCollection Children
        {
            get { return children; }
        }
        public Guid Guid
        {
            get { return guid; }
        }
        public virtual Type TargetObjectType
        {
            get { return typeof(IObject); }
        }
        public object Tag
        {
            get { return tag; }
            set { tag = value; }
        }
        public DescriptorBase(IXimlNode node, DescriptorBase parent, string guid)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            this.node = node;
            this.parent = parent;
            if (!Guid.TryParse(guid, out this.guid))
            {
                throw new ArgumentException("Parameter guid was not a valid Guid.");
            }
            if (this.parent != null)
            {
                this.parent.children.Add(this);
            }
        }
    }
}
